<template>
    <div class="app-container calendar-list-container">

        <!-- 查询和其他操作 -->
        <div class="filter-container">
          <!--<el-input clearable class="filter-item" style="width: 200px;" placeholder="平台编号" v-model="listQuery.platformId"></el-input>
          <el-input clearable class="filter-item" style="width: 200px;" placeholder="活动名称" v-model="listQuery.activityName"></el-input>
          <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">查找</el-button>-->
        </div>

        <!-- 查询结果 -->
        <el-table size="small" :data="list" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit highlight-current-row>
          <el-table-column align="center" min-width="150px" label="编号" prop="id">
          </el-table-column>   
          <el-table-column align="center" min-width="150px" label="预测类型" prop="name">
          </el-table-column>
          <el-table-column align="center" min-width="150px" label="金额" prop="amt">
          </el-table-column>
          <el-table-column align="center" label="操作" width="150" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button  type="primary" size="mini" v-if="loveCalculationAmtManager_btn_update"  @click="handleUpdate(scope.row)">详情</el-button>
              </template>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <div class="pagination-container">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page"
            :page-sizes="[10,20,30,50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
        </div>

        <!-- 添加对话框 -->
        <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
          <el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="100px" style='width: 400px; margin-left:50px;'>
            <el-form-item label="预测金额" prop="sort"> 
              <el-input type="text" v-model="dataForm.amt" clearable=""></el-input>
            </el-form-item>         
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取消</el-button>
            <el-button v-if="dialogStatus == 'update'" type="primary" @click="updateData('dataForm')">确定</el-button>
          </div>
        </el-dialog>
    </div>
</template>

<script>
import waves from '@/directive/waves' // 水波纹指令
import { page, putObj } from '@/api/cms/loveCalculation/amt'
import { mapGetters } from 'vuex'

export default {
  name: 'activity',
  directives: {
    waves
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        platformId: '',
        merchantId: ''
      },
      userList: [],
      list: [],
      total: 0,
      listLoading: false,
      dialogFormVisible: false,
      disabled: false,
      downloadLoading: false,
      loveCalculationAmtManager_btn_update: false,
      dataForm: {
      },
      textMap: {
        create: '创建',
        update: '编辑'
      },
      dialogStatus: '',
      rules: {
      }
    }
  },
  filters: {
  },
  created() {
    this.getList()
    this.loveCalculationAmtManager_btn_update = this.elements['loveCalculationAmtManager:btn_update']
  },
  computed: {
    ...mapGetters([
      'elements',
      'name'
    ])
  },

  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      console.log('页码改变页码改变页码改变页码改变')
      console.log(val)
      this.listQuery.page = val
      this.getList()
    },
    getList() {
      this.listLoading = true
      this.listQuery.platformId = this.platformId
      console.log('+++++++++++++++++++++++++++++++++')
      console.log(this.listQuery)
      page(this.listQuery).then(response => {
        console.log(response)
        this.list = response.data.rows
        this.total = response.data.total
        this.listLoading = false
      }).catch(() => {
        this.list = []
        this.total = 0
        this.listLoading = false
      })
    },
    handleUpdate(row) {
      this.dataForm = row
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.disabled = true
    },
    updateData(formName) {
      putObj(this.dataForm.id, this.dataForm).then(() => {
        this.$notify({
          title: '成功',
          message: '更新成功',
          type: 'success',
          duration: 2000
        })
        this.getList()
        this.dialogFormVisible = false
      })
    },
    handleCreate() {
      this.resetForm()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.disabled = false
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    handleDetail(row) {

    },
    handleClose(row) {
    },
    resetForm() {
      this.dataForm = {
      }
    }
  }
}
</script>

<style>

</style>


